package com.myproject.sbp.order.controller;

import com.myproject.sbp.base.auth.AuthPermission;
import com.myproject.sbp.member.model.Member;
import com.myproject.sbp.order.api.feign.MemberServiceFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;
    @Resource
    private MemberServiceFeign memberServiceFeign;

    @Value("${server.port}")
    String port;

    @AuthPermission
    @GetMapping("/test")
    public Object test(){
        return "order操作成功";
    }

    /**
     * 测试负载均衡Ribbon
     */
    @GetMapping("/test1")
    public Object test1(){
        restTemplate.getForObject("http://module-member/test1", Void.class);
        return "当前post：" + port;
    }

    /**
     * 测试负载均衡Ribbon
     */
    @GetMapping("/test2")
    public Object test2(){
        List<Member> list = memberServiceFeign.queryMemberList();
        return "当前post：" + port;
    }

}